package com.ww.springboot.boot.algorithm.leetcode1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-05-05 09:14
 */
public class BZ二维码模拟生成 extends JFrame {

    public BZ二维码模拟生成() {
        add(new BZ二维码模拟生成.composition());
    }

    private static final int[][] index = new int[32][32];

    /**
     * 1.将字符串转换为byte[](对应一种将内容转换为byte[]的算法);
     * 2.将byte[]转换为二进制数组,再将二进制数组转换为码图;
     * 3.生成过程中可以自定义自己的加解密方式 或混淆方法;
     * 4.扫描时反向解析即可;
     *
     *
     * @param args
     */
    public static void main(String[] args) {
        //1.将数字转换为16位的二进制;代表4*4区域的取值
        JFrame frame = new BZ二维码模拟生成();
        frame.setTitle("二维码生成");
        frame.setSize(830, 600);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        //获取输入内容
        String ss = "测试";
        //将内容转成字节流
        byte[] bytes = ss.getBytes();

        java.util.List<Integer> list = new ArrayList<>();
        //根据index生成相应数量的数据


    }

    static class composition extends JPanel {

        public composition() {

            Timer timer = new Timer(100, new BZ二维码模拟生成.composition.BallMoveListener());
            timer.start();
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            g.setColor(Color.BLACK);

            int multiple = 8;

            //画正方形
            for (int i = 0; i < 100; i++) {
                for (int j = 0; j < 100; j++) {
                    if (index[i][j] == 0) {
                        g.drawRect(100 + i * multiple, 100 + j * multiple, multiple, multiple);
                    } else {
                        g.fillRect(100 + i * multiple, 100 + j * multiple, multiple, multiple);
                    }

                }
            }
        }

        class BallMoveListener implements ActionListener {
            @Override
            public void actionPerformed(ActionEvent e) {
                //重画
                repaint();
            }
        }
    }
}
